package com.lanou.dllo.findfood.adpter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.dllo.findfood.entity.FindTopResult;
import com.lanou.dllo.findfood.fragment.FindTopFragemnt;

import java.util.List;

/**
 * Created by dllo on 15/10/28.
 */
public class FindViewperApter extends FragmentPagerAdapter{
    private List<FindTopResult> resultList;

    public void  add(List<FindTopResult> results)
    {
        resultList = results;
        notifyDataSetChanged();
    }
    public FindViewperApter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        FindTopResult result = resultList.get(position % resultList.size());
        String title = result.getTitle();
        String imgUrl = "http://tnfs.tngou.net/image/" + result.getImg();
        int id = result.getId();
        return FindTopFragemnt.getInstance(title,imgUrl,id);
    }

    @Override
    public int getCount() {
        return resultList!= null && resultList.size() > 0 ? Integer.MAX_VALUE :0;
    }


}
